from multiprocessing import Process
import mmap
import contextlib
import time


def writer_obj(obj):
    with contextlib.closing(mmap.mmap(-1, 1024, tagname='cnblogs', access=mmap.ACCESS_WRITE)) as mem:
        mem.seek(0)
        print('Write data:== %s == to share memory!' % obj)
        mem.write(bytes(obj, encoding='utf-8'))
        mem.flush()
        time.sleep(0.5)


def writer():
    i = 0
    while True:
        time.sleep(1)
        i = i + 1
        writer_obj("%s" % i)


if __name__ == '__main__':
    p_writer = Process(target=writer, args=())
    p_writer.start()
    p_writer.join()
